var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/helpers/defineProperty")),
  e = require("../../services/api.js"),
  a = require("../../utils/util.js"),
  url = require("../../services/baseURL.js");

Page({
  data: {
    active: 0,
    lists: [],
    types: [],
    pageTotal: [],
    pageNum: []
  },
  onLoad: function(t) {
    var e = this;
    this.setData({
      active: t.active || 0
    }, function() {
      e.getStoreTypes();
    });
  },
  getStoreTypes: function() {
    var t = this,
      a = wx.getStorageSync("store-type");
    a ? this.setData({
      types: a,
      pageNum: Array(a.length + 1).fill(1),
      pageTotal: Array(a.length + 1).fill(0)
    }, function() {
      t.getStores();
    }) : (0, e.getStoreType)().then(function(e) {
      200 === e.data.code && (t.setData({
        types: e.data.data,
        pageNum: Array(e.data.data.length + 1).fill(1),
        pageTotal: Array(e.data.data.length + 1).fill(0)
      }, function() {
        t.getStores();
      }), wx.setStorageSync("store-type", e.data.data));
    });
  },
  getStores: function() {
    var n = this,
      i = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 1,
      o = (0,
        a.getLocation)(),
      s = this.data.active,
      r = this.data.types[s - 1],
      l = {
        lng: o.longitude,
        lat: o.latitude,
        type: r ? r.id : null,
        pageSize: 8,
        page: i
      };
    r || delete l.type, (0, e.getTaskLists)(l).then(function(e) {
      if (200 === e.data.code) {
        var a, o = e.data.data.list.map(function(t) {
          return t.money = parseInt(t.money), t.isend = parseInt(t.last_total_task) <= 0,
            t;
        });
        n.setData((a = {}, (0, t.default)(a, "lists[".concat(s, "]"), i > 1 ? [].concat(n.data.lists[s], o) : o),
          (0, t.default)(a, "pageTotal[".concat(s, "]"), e.data.data.count), (0, t.default)(a, "pageNum[".concat(s, "]"), i),
          a));
      }
    });
  },
  typeChange: function(t) {
    var e = this;
    this.setData({
      active: t.currentTarget.dataset.id
    }, function() {
      e.getStores();
    });
  },
  onReady: function() {},
  onShow: function() {},
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {
    var t = this.selectComponent("#pagination");
    if (!t) return !1;
    var e = t.hasMore();
    e && this.getStores(e);
  },
  onShareAppMessage: function() {}
});